package main

import (
	"fmt"
	"go.web.demo.com/web/rpc_client"

	"net/http"

	"github.com/gin-gonic/gin"
	"go.web.demo.com/web/config"
	"go.web.demo.com/web/controller"
	"go.web.demo.com/web/middleware"

	_ "denglibin.io/common/log"
)

// 启动远程调用客户端
func startRpcx() {
	rpc_client.StartRpcxClient()
}

//启动web程序
func startWeb() {
	//获取配置信息
	conf := config.GetApplicationConfig()
	gin.SetMode(conf.Mod)
	e := gin.Default()
	//静态资源目录
	e.StaticFS("/"+conf.UploadDir, http.Dir(conf.UploadDir))
	e.StaticFS("/static", http.Dir("static"))
	e.StaticFile("/", "index.html")
	//注册中间件
	middleware.RegisterMiddleware(e, conf)
	//注册controller
	controller.RegisterController(e)

	//运行web服务
	err := e.Run(fmt.Sprintf(":%d", conf.Port))

	//使用https
	/*if instance.ApplicationConfig.Https {
		err = e.RunTLS(fmt.Sprintf(":%d", instance.ApplicationConfig.Port), "cert.pem", "key.pem")
	} else {
		err = e.Run(fmt.Sprintf(":%d", instance.ApplicationConfig.Port))
	}*/

	panic(err)
}

//程序入口
func main() {
	startRpcx()
	startWeb()
}
